package echat.future.cn.echat.my.weight.dialog;

import android.app.Dialog;
import android.content.Context;
import android.support.annotation.NonNull;
import android.view.Display;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.TextView;

import echat.future.cn.echat.R;

public class ChoseDialog extends Dialog {

    public ChoseDialog(@NonNull Context context) {
        this(context, R.style.bootomDialog);
    }

    public ChoseDialog(@NonNull Context context, int themeResId) {
        super(context, themeResId);
    }


    public static class Builder{
        private Dialog dialog;
        private Context mContext;
        private String context;
        private View.OnClickListener rightClickListener;
        private int cancelColor = -1;
        private int confirmColor =  -1;
        public Builder(Context context){
            this.mContext = context;
        }

        public Builder content(String hintString){
            this.context = hintString;
            return this;
        }

        public Builder rightListener(View.OnClickListener onClickListener){
            this.rightClickListener = onClickListener;
            return this;
        }

        public Builder cancelColor(int color){
            this.cancelColor =color;
            return this;
        }

        public Builder comfirmColor(int color){
            this.confirmColor = color;
            return this;
        }

        public Dialog Builder(){
            LayoutInflater inflater = LayoutInflater.from(mContext);
            View rootView = inflater.inflate(R.layout.dialog_chose,null,false);
            TextView textView = rootView.findViewById(R.id.hint);
            textView.setText(context);
            TextView cancel = rootView.findViewById(R.id.cancel);
            cancel.setOnClickListener(v->{dialog.dismiss();});
            TextView comfirm = rootView.findViewById(R.id.confirm);
            comfirm.setOnClickListener(rightClickListener);
            if(cancelColor!=-1){
                cancel.setTextColor(cancelColor);
            }

            if(confirmColor!=-1){
                comfirm.setTextColor(confirmColor);
            }


            dialog = new ChoseDialog(mContext);
            dialog.setContentView(rootView);
            Window window = dialog.getWindow();
            window.setGravity(Gravity.CENTER);

            WindowManager m = window.getWindowManager();
            Display d = m.getDefaultDisplay(); //为获取屏幕宽、高
            WindowManager.LayoutParams p = dialog.getWindow().getAttributes(); //获取对话框当前的参数值
            p.width = WindowManager.LayoutParams.WRAP_CONTENT;
            p.height = WindowManager.LayoutParams.WRAP_CONTENT;
            dialog.getWindow().setAttributes(p); //设置生效
            dialog.setCancelable(false);
            return dialog;
        }

    }

}
